/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package User;

import Bean.adminBeanRemote;
import Objects.User;
import java.util.List;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

/**
 *
 * @author tinvukhac
 */
public class AdminController extends MultiActionController {
    
    InitialContext context;
    
    public ModelAndView admin(HttpServletRequest request,
            HttpServletResponse response)
    {
        ModelAndView view = new ModelAndView("admin");
        
        try{
            context = new InitialContext();
            adminBeanRemote adminBean = (adminBeanRemote) context.lookup("adminBean");
            List<User> userList = adminBean.getUserReportInfo();
            view.addObject("userList", userList);
        } catch (Exception e) {
        }
        
        return view;
    }
    
    public void blockUser(HttpServletRequest request,
            HttpServletResponse response)
    {
        String userId = request.getParameter("userId");
        String type = request.getParameter("type");
        try{
            context = new InitialContext();
            adminBeanRemote adminBean = (adminBeanRemote) context.lookup("adminBean");
            adminBean.blockUser(userId, type);
            response.sendRedirect(request.getContextPath() + "/admin/admin.htm");
        } catch (Exception e) {
        }
    }
    
    public void unblockUser(HttpServletRequest request,
            HttpServletResponse response)
    {
        String userId = request.getParameter("userId");
        try{
            context = new InitialContext();
            adminBeanRemote adminBean = (adminBeanRemote) context.lookup("adminBean");
            adminBean.unblockUser(userId);
            response.sendRedirect(request.getContextPath() + "/admin/admin.htm");
        } catch (Exception e) {
        }
    }
}
